import { Field, InputType, ObjectType, PartialType, registerEnumType } from "@nestjs/graphql";
import { BaseCreateSchema, PageInput, PaginatedResponse, SearchInput } from "src/common/mongodb/commonSchema";
import { Power } from "../entities/power.entity";
import { GraphQLBigInt } from 'graphql-scalars';
import { MongoQueryScalar } from "src/common/scalars/mongo.query.scalar";

export enum Operation {
  SHOW = "SHOW",
  ADD = "ADD",
  UPDATE = "UPDATE",
  DELETE = "DELETE",
  EXPORT = "EXPORT",
  IMPORT = "IMPORT",
}

registerEnumType(Operation, {
  name: 'Operation', // 这是 GraphQL 枚举类型的名称
  description: '操作权限 SHOW-查看 ADD-添加 UPDATE-修改 DELETE-删除', // 可选描述
})

/** 创建输入DTO */
@InputType()
export class CreatePowerInput extends BaseCreateSchema {
  @Field(() => String) name: string;

  @Field(() => String) code: string;

  @Field(() => GraphQLBigInt) menu: number;

  @Field(() => [Operation]) operation: Operation[];

  @Field(() => String) explain: string;
}

/** 更新输入DTO */
@InputType()
export class UpdatePowerInput extends PartialType(CreatePowerInput) {
  @Field(() => GraphQLBigInt)
  _id: number;
}

/** 搜索输入DTO */
@InputType()
export class SearchPowerInput {
  @Field(() => GraphQLBigInt, { nullable: true }) _id: number;

  @Field(() => MongoQueryScalar) name: string;
}

/** 搜索输入&排序输入 */
@InputType()
export class SearchPowerSortInput extends SearchInput<SearchPowerInput>(SearchPowerInput) {
}

/** 分页查询输入DTO */
@InputType()
export class PagePowerInput extends PageInput<SearchPowerInput>(SearchPowerInput) {
}

@ObjectType()
export class PagePowerResponse extends
  PaginatedResponse<Power>(Power) {
}





